<template>
  <div class="page">
    <div class="page-header">
      <h2 class="page-title">个人中心</h2>
    </div>

    <!-- 用户信息 -->
    <div class="user-info card">
      <div class="user-avatar">👤</div>
      <div class="user-details">
        <div class="user-name">{{ userInfo.username }}</div>
        <div class="user-email">{{ userInfo.email }}</div>
      </div>
    </div>

    <!-- 功能菜单 -->
    <div class="menu-section">
      <div class="menu-group">
        <div class="menu-item" @click="goToOrders">
          <div class="menu-icon">📦</div>
          <div class="menu-text">我的订单</div>
          <div class="menu-arrow">></div>
        </div>
        <div class="menu-item" @click="goToAddresses">
          <div class="menu-icon">📍</div>
          <div class="menu-text">收货地址</div>
          <div class="menu-arrow">></div>
        </div>
        <div class="menu-item" @click="goToFavorites">
          <div class="menu-icon">❤️</div>
          <div class="menu-text">我的收藏</div>
          <div class="menu-arrow">></div>
        </div>
      </div>

      <div class="menu-group">
        <div class="menu-item" @click="goToSettings">
          <div class="menu-icon">⚙️</div>
          <div class="menu-text">设置</div>
          <div class="menu-arrow">></div>
        </div>
        <div class="menu-item" @click="goToHelp">
          <div class="menu-icon">❓</div>
          <div class="menu-text">帮助中心</div>
          <div class="menu-arrow">></div>
        </div>
        <div class="menu-item" @click="goToAbout">
          <div class="menu-icon">ℹ️</div>
          <div class="menu-text">关于我们</div>
          <div class="menu-arrow">></div>
        </div>
      </div>

      <div class="menu-group">
        <div class="menu-item logout" @click="logout">
          <div class="menu-icon">🚪</div>
          <div class="menu-text">退出登录</div>
          <div class="menu-arrow">></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'

const router = useRouter()
const userStore = useUserStore()

// 使用计算属性获取用户信息
const userInfo = computed(() => {
  if (userStore.user) {
    return {
      username: userStore.user.username || '未知用户',
      email: userStore.user.email || '未知邮箱',
      avatar: userStore.user.avatar || ''
    }
  } else {
    return {
      username: '未登录',
      email: '请先登录',
      avatar: ''
    }
  }
})

const goToOrders = () => {
  router.push('/order')
}

const goToAddresses = () => {
  router.push('/address')
}

const goToFavorites = () => {
  alert('跳转到收藏页面')
}

const goToSettings = () => {
  alert('跳转到设置页面')
}

const goToHelp = () => {
  alert('跳转到帮助页面')
}

const goToAbout = () => {
  alert('跳转到关于页面')
}

const logout = () => {
  userStore.logout()
  router.push('/login')
}
</script>

<style scoped>
.user-info {
  display: flex;
  align-items: center;
  padding: 30px 20px;
}

.user-avatar {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-right: 20px;
}

.user-details {
  flex: 1;
}

.user-name {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin-bottom: 5px;
}

.user-email {
  font-size: 14px;
  color: #666;
}

.menu-section {
  margin-top: 20px;
}

.menu-group {
  background: #fff;
  border-radius: 8px;
  margin-bottom: 20px;
  overflow: hidden;
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.menu-item:last-child {
  border-bottom: none;
}

.menu-item:hover {
  background-color: #f5f5f5;
}

.menu-item.logout {
  color: #ff3b30;
}

.menu-icon {
  font-size: 20px;
  margin-right: 15px;
  width: 24px;
  text-align: center;
}

.menu-text {
  flex: 1;
  font-size: 16px;
}

.menu-arrow {
  color: #ccc;
  font-size: 16px;
}
</style> 